﻿/// ZaxControls
/// Programmed by Leland Ede
/// Website: http://www.zaxisstudios.com
/// E-Mail: codeplex@zaxis-studios.com
/// Create: 3/29/2014
/// Modified: 4/09/2014

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ZaxLib.Web.Writers.Nodes;

namespace ZaxLib.Web.UI.WebControls
{
	[DefaultProperty("Text")]
	[ToolboxData("<{0}:DatePicker runat=server></{0}:DatePicker>")]
	public class DatePicker : ZaxControl
	{
		#region Parameters

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public String Name
		{
			get
			{
				String s = ViewState["Name"] as String;
				return (s == null ? String.Empty : s);
			}
			set
			{
				ViewState["Name"] = value;
			}
		}

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public String DateClass
		{
			get
			{
				String s = ViewState["Class"] as String;
				return (s == null ? String.Empty : s);
			}
			set
			{
				ViewState["Class"] = value;
			}
		}

		[Bindable(true)]
		[Category("Appearance")]
		[DefaultValue("")]
		[Localizable(true)]
		public String Size
		{
			get
			{
				String s = ViewState["Size"] as String;
				return (s == null ? "10" : s);
			}
			set
			{
				ViewState["Size"] = value;
			}
		}

		public String DateID
		{
			get
			{
				return String.Format("Date_{0}", ID);
			}
		}

		#endregion

		#region Writer Methods
	
		protected override void ControlWrite(HtmlTextWriter writer)
		{
			// Add text box to page
			writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
			writer.AddAttribute(HtmlTextWriterAttribute.Id, DateID);
			writer.AddAttribute(HtmlTextWriterAttribute.Size, Size);
			writer.AddAttribute(HtmlTextWriterAttribute.Value, Text);
			writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "ReadOnly");
			writer.RenderBeginTag(HtmlTextWriterTag.Input);
			writer.Write("\n");
			writer.RenderEndTag();
		}

		protected override void PostWrite(HtmlTextWriter writer)
		{
			base.PostWrite(writer);

			CodeWriter.CreateTopNode();
			CodeWriter.AddChild(DateID).SelectorId();
			CodeWriter.AddChild("datepicker").Joined();
			CodeWriter.AddParam("");
		}

		#endregion

		protected override void RenderContents(HtmlTextWriter writer)
		{
			base.RenderContents(writer);
		}
	}
}
